import {z} from 'zod' export type Interaction = {id?: string | undefined, accountId?: string | undefined, start?: ({quantity?: number | undefined, from?: ('start' | 'end') | undefined, unit?: ('percent' | 'seconds') | undefined}) | undefined, end?: ({quantity?: number | undefined, from?: ('start' | 'end') | undefined, unit?: ('percent' | 'seconds') | undefined}) | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, type: 'Link' | 'Card' | 'External', durationType?: ('point' | 'span' | 'end' | 'full') | undefined, experience?: string | undefined, placement?: ('top-left' | 'top-right' | 'bottom-left' | 'bottom-right') | undefined, text?: string | undefined, href?: string | undefined, title?: string | undefined, description?: string | undefined, img?: string | undefined}; export type CreateApiAccountsAccountIdInteractionsArgs = {body: Interaction}; export type CreateApiAccountsAccountIdInteractionsOptions = {baseUrl?: string | undefined, BCOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const interaction = z.object({id: z.string().optional(), accountId: z.string().optional(), start: z.object({quantity: z.number().optional(), from: z.enum(["start", "end"]).optional(), unit: z.enum(["percent", "seconds"]).optional()}).optional(), end: z.object({quantity: z.number().optional(), from: z.enum(["start", "end"]).optional(), unit: z.enum(["percent", "seconds"]).optional()}).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), type: z.enum(["Link", "Card", "External"]), durationType: z.enum(["point", "span", "end", "full"]).optional(), experience: z.string().optional(), placement: z.enum(["top-left", "top-right", "bottom-left", "bottom-right"]).optional(), text: z.string().optional(), href: z.string().optional(), title: z.string().optional(), description: z.string().optional(), img: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create In-Page Experience Interaction * * POST /accounts/{{account_id}}/interactions */ export const createApiAccountsAccountIdInteractions = async (args: CreateApiAccountsAccountIdInteractionsArgs, options?: CreateApiAccountsAccountIdInteractionsOptions) => { const {baseUrl = "https://experiences.api.brightcove.com/v1", fetch: fetchFn = fetch, BCOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BCOAuth2 !== undefined) headers.set('authorization', `Bearer ${BCOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args['{account_id']))}}/interactions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(interaction, await res.json()) };